﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinFormsAppTest.pojo;

namespace WinFormsAppTest.Service
{
    internal class FormService
    {
        /////////////////   加载表格中的数据   开始   //////////////////////


        //加载人事档案表格中全部的数据
        public DataGridView Form_Filesdata_Loading(DataGridView UserdataGridView)
        {
            //开始添加表格中的数据
            FilesService fileservice = new FilesService();

            List<WinFormsAppTest.Class.Files> files = new List<WinFormsAppTest.Class.Files>();
            files = fileservice.GetFiles();

            int _i = files.Count - 1;
            if (files.Count == 0)
            {
                MessageBox.Show("用户档案信息无法查询!");
            }
            //升序版
            for (int j = 0; j < files.Count; j++)
            {
                Class.Files f = files[j];
                int myNewRowIndex = UserdataGridView.Rows.Add();
                UserdataGridView.Rows[myNewRowIndex].Cells["FileIdColumn"].Value = f.fileid;
                UserdataGridView.Rows[myNewRowIndex].Cells["MsgColumn"].Value = f.msg;
                UserdataGridView.Rows[myNewRowIndex].Cells["HouseColumn"].Value = f.house;
                UserdataGridView.Rows[myNewRowIndex].Cells["ContractColumn"].Value = f.contract;
                UserdataGridView.Rows[myNewRowIndex].Cells["InsureColumn"].Value = f.insure;
                UserdataGridView.Rows[myNewRowIndex].Cells["UserIdColumn"].Value = f.userid;
                UserdataGridView.Rows[myNewRowIndex].Cells["UpdateColumn"].Value = "更新";
                UserdataGridView.Rows[myNewRowIndex].Cells["DeleteColumn"].Value = "删除";
            }
            return UserdataGridView;
        }
        //


        //加载通过用户id在files表中搜索
        public DataGridView GetFilesDataByUserId(DataGridView table, int id)
        {
            table.Rows.Clear();
            //开始添加数据
            FilesService fileservice = new FilesService();

            List<WinFormsAppTest.Class.Files> files = new List<WinFormsAppTest.Class.Files>();
            files = fileservice.GetFilesByUserId(id);

            int _i = files.Count - 1;
            if (files.Count == 0)
            {
                MessageBox.Show("用户信息无法查询!");
                return table;
            }

            for (int j = 0; j < files.Count; j++)
            {
                WinFormsAppTest.Class.Files f = files[j];
                int myNewRowIndex = table.Rows.Add();
                table.Rows[myNewRowIndex].Cells["FileIdColumn"].Value = f.fileid;
                table.Rows[myNewRowIndex].Cells["MsgColumn"].Value = f.msg;
                table.Rows[myNewRowIndex].Cells["HouseColumn"].Value = f.house;
                table.Rows[myNewRowIndex].Cells["ContractColumn"].Value = f.contract;
                table.Rows[myNewRowIndex].Cells["InsureColumn"].Value = f.insure;
                table.Rows[myNewRowIndex].Cells["UserIdColumn"].Value = f.userid;
                table.Rows[myNewRowIndex].Cells["UpdateColumn"].Value = "更新";
                table.Rows[myNewRowIndex].Cells["DeleteColumn"].Value = "删除";
            }
            //
            return table;
        }



        //加载全部人事变动表格
        public DataGridView Form_Changesdata_Loading(DataGridView table)
        {
            table.Rows.Clear();
            //开始添加数据
            ChangeService changeservice = new ChangeService();

            List<Change> change = new List<Change>();
            change = changeservice.GetChanges();

            int _i = change.Count - 1;
            if (change.Count == 0)
            {
                MessageBox.Show("用户信息无法查询!");
                return table;
            }

            for (int j = 0; j < change.Count; j++)
            {
                Change f = change[j];
                int myNewRowIndex = table.Rows.Add();
                table.Rows[myNewRowIndex].Cells["ChangeIdColumn"].Value = f.Changeid;
                table.Rows[myNewRowIndex].Cells["TypeColumn"].Value = f.Type;
                table.Rows[myNewRowIndex].Cells["TimeColumn"].Value = f.Time;
                table.Rows[myNewRowIndex].Cells["UserIdColumn"].Value = f.Userid;
                table.Rows[myNewRowIndex].Cells["UpdateColumn"].Value = "更新";
                table.Rows[myNewRowIndex].Cells["DeleteColumn"].Value = "删除";
            }
            //
            return table;
        }
        //



        //加载全部考核奖惩
        public DataGridView Form_Examdata_Loading(DataGridView table)
        {
            table.Rows.Clear();
            //开始添加数据
            ExamService examservice = new ExamService();

            List<Exam> exam = new List<Exam>();
            exam = examservice.GetExams();

            int _i = exam.Count - 1;
            if (exam.Count == 0)
            {
                MessageBox.Show("用户信息无法查询!");
                return table;
            }

            for (int j = 0; j < exam.Count; j++)
            {
                Exam f = exam[j];
                int myNewRowIndex = table.Rows.Add();
                table.Rows[myNewRowIndex].Cells["ExamIdColumn"].Value = f.Examid;
                table.Rows[myNewRowIndex].Cells["StateColumn"].Value = f.State;
                table.Rows[myNewRowIndex].Cells["MeasureColumn"].Value = f.Measure;
                table.Rows[myNewRowIndex].Cells["GoalColumn"].Value = f.Goal;
                table.Rows[myNewRowIndex].Cells["UserIdColumn"].Value = f.Userid;
                table.Rows[myNewRowIndex].Cells["UpdateColumn"].Value = "更新";
                table.Rows[myNewRowIndex].Cells["DeleteColumn"].Value = "删除";
            }
            //
            return table;
        }
        //



        //全部出差信息
        public DataGridView Form_Outtimesdata_Loading(DataGridView table)
        {
            table.Rows.Clear();
            //开始添加数据
            OuttimeService examservice = new OuttimeService();

            List<Outtime> outtime = new List<Outtime>();
            outtime = examservice.GetOuttimes();

            int _i = outtime.Count - 1;
            if (outtime.Count == 0)
            {
                MessageBox.Show("用户信息无法查询!");
                return table;
            }

            for (int j = 0; j < outtime.Count; j++)
            {
                Outtime f = outtime[j];
                int myNewRowIndex = table.Rows.Add();
                table.Rows[myNewRowIndex].Cells["OutIdColumn"].Value = f.Outid;
                table.Rows[myNewRowIndex].Cells["BeginTimeColumn"].Value = f.Begintime;
                table.Rows[myNewRowIndex].Cells["EndTimeColumn"].Value = f.Endtime;
                table.Rows[myNewRowIndex].Cells["PlaceColumn"].Value = f.Place;
                table.Rows[myNewRowIndex].Cells["WorkIdColumn"].Value = f.Workid;
                table.Rows[myNewRowIndex].Cells["UserIdColumn"].Value = f.Userid;
                table.Rows[myNewRowIndex].Cells["UpdateColumn"].Value = "更新";
                table.Rows[myNewRowIndex].Cells["DeleteColumn"].Value = "删除";
            }
            //
            return table;
        }
        //


        public DataGridView Form_Signssdata_Loading(DataGridView table)
        {
            table.Rows.Clear();
            //开始添加数据
            SignsService examservice = new SignsService();

            List<Signs> outtime = new List<Signs>();
            outtime = examservice.GetSignss();

            int _i = outtime.Count - 1;
            if (outtime.Count == 0)
            {
                MessageBox.Show("用户信息无法查询!");
                return table;
            }

            for (int j = 0; j < outtime.Count; j++)
            {
                Signs f = outtime[j];
                int myNewRowIndex = table.Rows.Add();
                table.Rows[myNewRowIndex].Cells["OutIdColumn"].Value = f.Signid;
                table.Rows[myNewRowIndex].Cells["BeginTimeColumn"].Value = f.Begintime;
                table.Rows[myNewRowIndex].Cells["EndTimeColumn"].Value = f.Endtime;
                table.Rows[myNewRowIndex].Cells["WorkIdColumn"].Value = f.Workid;
                table.Rows[myNewRowIndex].Cells["UserIdColumn"].Value = f.Userid;
                table.Rows[myNewRowIndex].Cells["UpdateColumn"].Value = "更新";
                table.Rows[myNewRowIndex].Cells["DeleteColumn"].Value = "删除";
            }
            //
            return table;
        }
        //



        public DataGridView Form_Overtimesdata_Loading(DataGridView table)
        {
            table.Rows.Clear();
            //开始添加数据
            OvertimeService examservice = new OvertimeService();

            List<Overtime> outtime = new List<Overtime>();
            outtime = examservice.GetOvertimes();

            int _i = outtime.Count - 1;
            if (outtime.Count == 0)
            {
                MessageBox.Show("用户信息无法查询!");
                return table;
            }

            for (int j = 0; j < outtime.Count; j++)
            {
                Overtime f = outtime[j];
                int myNewRowIndex = table.Rows.Add();
                table.Rows[myNewRowIndex].Cells["OutIdColumn"].Value = f.Overid;
                table.Rows[myNewRowIndex].Cells["BeginTimeColumn"].Value = f.Begintime;
                table.Rows[myNewRowIndex].Cells["EndTimeColumn"].Value = f.Endtime;
                table.Rows[myNewRowIndex].Cells["WorkIdColumn"].Value = f.Workid;
                table.Rows[myNewRowIndex].Cells["UserIdColumn"].Value = f.Userid;
                table.Rows[myNewRowIndex].Cells["UpdateColumn"].Value = "更新";
                table.Rows[myNewRowIndex].Cells["DeleteColumn"].Value = "删除";
            }
            //
            return table;
        }
        //


        ////////////////////加载表格中的数据   结束   ////////////////////
    }
}
